package graphics.pixelbender.src 
{
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Shader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.ShaderFilter;
	import flash.utils.setInterval;
	import samples.BaseSample;
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class Slices extends BaseSample
	{
		
		[Embed(source='../../../../lib/chatquilouche2.jpg')]private var src:Class;
		private var image:Bitmap;
		
		[Embed(source='../pbj/slices.pbj', mimeType='application/octet-stream')]private var shaderPBJ:Class;
		private var shader:Shader;
		private var filter:ShaderFilter;
		
		public function Slices() 
		{
			
			shader = new Shader(  new shaderPBJ() );
			filter = new ShaderFilter( shader );
			
			image = new Bitmap( Bitmap( new src() ).bitmapData );
			addChild( image );
			
			center();
			
			interval = setInterval( update, 30 );
			
		}
		
		private function update( e:Event = null  ) : void
		{
			
			shader.data.horizontal.value = [ mouseX / 8 ];
			shader.data.vertical.value = [ mouseY / 8 ];
			image.filters = [ filter ];
			
		}
	}
}